package cn.iocoder.yudao.module.erp.controller.app.erpSupplier;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierSaveReqVO;
import cn.iocoder.yudao.module.erp.controller.app.auth.vo.AppErpSupplierSaveReqVO;
import cn.iocoder.yudao.module.erp.controller.app.erpSupplier.vo.AppErpSupplierUpdatePasswordReqVO;
import cn.iocoder.yudao.module.erp.controller.app.erpSupplier.vo.AppErpSupplierUpdateReqVO;
import cn.iocoder.yudao.module.erp.controller.app.erpSupplier.vo.ErpSupplierInfoRespVO;
import cn.iocoder.yudao.module.erp.controller.app.erpSupplier.vo.ExceptionRemarkUpdateReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO;
import cn.iocoder.yudao.module.erp.enums.ErpSupplierStatus;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "APP - ERP供应商信息接口")
@RestController
@RequestMapping("/erp/supplier/app")
@Validated
@Slf4j
public class AppErpSupplierController {

    @Resource
    private ErpSupplierService erpSupplierService;



    @GetMapping("/page")
    @Operation(summary = "供应商分页")
    public CommonResult<PageResult<ErpSupplierRespVO>> getSupplierPage(@Valid ErpSupplierPageReqVO pageReqVO) {
        PageResult<ErpSupplierDO> pageResult = erpSupplierService.getSupplierPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ErpSupplierRespVO.class));
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP 供应商")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<ErpSupplierRespVO> getSupplier(@RequestParam("id") Long id) {
        ErpSupplierDO supplier = erpSupplierService.getSupplier(id);
        return success(BeanUtils.toBean(supplier, ErpSupplierRespVO.class));
    }

    @PostMapping("/updateExceptionRemark")
    @Operation(summary = "更新ERP 供应商异常备注")
    public CommonResult<Boolean> updateExceptionRemark(@Valid @RequestBody ExceptionRemarkUpdateReqVO updateReqVO) {
        erpSupplierService.updateExceptionRemark(updateReqVO);
        return success(true);
    }


    @GetMapping("/exceptionPage")
    @Operation(summary = "供应商异常分页")
    public CommonResult<PageResult<ErpSupplierRespVO>> exceptionPage(@Valid ErpSupplierPageReqVO pageReqVO) {
        pageReqVO.setStatus(ErpSupplierStatus.PASS.getStatus());
        PageResult<ErpSupplierDO> pageResult = erpSupplierService.getSupplierPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ErpSupplierRespVO.class));
    }



}
